#region File Description
//-----------------------------------------------------------------------------
// OptionsMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace ScreenManagement
{
    /// <summary>
    /// The options screen is brought up over the top of the main menu
    /// screen, and gives the user a chance to configure the game
    /// in various hopefully useful ways.
    /// </summary>
    class HowToPlayScreen : MenuScreen
    {
        #region Fields
        ContentManager content;
        SpriteFont spriteFont;
        Texture2D howtoPawn1;
        Texture2D howtoPawn2;
        Texture2D howtoRook;
        Texture2D howtoKnight;
        Texture2D howtoBishop;
        Texture2D howtoQueen;
        Texture2D howtoKing;
        int yRoot = 92;
        double timeSinceIncrement = 0.0f;
        bool exiting = false;// this is to hide images as the screen is fading on "ExitScreen"
        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public HowToPlayScreen()
            : base("")
        {

            //MenuEntry back = new MenuEntry("Back");

            //back.Selected += OnCancel;
            
            //MenuEntries.Add(back);
        }

        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            spriteFont = content.Load<SpriteFont>("Fonts/howtofont");
            howtoPawn1 = content.Load<Texture2D>("Textures/howtopawn1");
            howtoPawn2 = content.Load<Texture2D>("Textures/howtopawn2");
            howtoRook = content.Load<Texture2D>("Textures/howtorook");
            howtoKnight = content.Load<Texture2D>("Textures/howtoknight");
            howtoBishop = content.Load<Texture2D>("Textures/howtobishop");
            howtoQueen = content.Load<Texture2D>("Textures/howtoqueen");
            howtoKing = content.Load<Texture2D>("Textures/howtoking");
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            if (timeSinceIncrement <= 0.03f)
                timeSinceIncrement += gameTime.ElapsedGameTime.TotalSeconds;

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        public override void Draw(GameTime gameTime)
        {
            if (!exiting)
            {
                this.ScreenManager.SpriteBatch.Begin();

                this.ScreenManager.SpriteBatch.Draw(howtoPawn1, new Rectangle(20, yRoot, 500, 352), Color.White);
                this.ScreenManager.SpriteBatch.DrawString(spriteFont, " Pawns in Glinski capture orthogonally, and move up ranks. \n They can advance twice from a starting position. \n En passant applies.", new Vector2(520, yRoot), Color.White);

                this.ScreenManager.SpriteBatch.Draw(howtoPawn2, new Rectangle(20, yRoot + (352 * 1), 500, 352), Color.White);
                this.ScreenManager.SpriteBatch.DrawString(spriteFont, " Pawns in McCooey/Shafran capture orthogonally up one rank, \n and move up ranks. They can advance twice from \n a starting position in McCooey, up to three in Shafran. \n En passant applies.", new Vector2(520, yRoot + (352 * 1)), Color.White);

                this.ScreenManager.SpriteBatch.Draw(howtoRook, new Rectangle(20, yRoot + (352 * 2), 500, 352), Color.White);
                this.ScreenManager.SpriteBatch.DrawString(spriteFont, " Rooks move diagonally in six directions and can castle in \n Shafran games, both long/short, king/queen side.", new Vector2(520, yRoot + (352 * 2)), Color.White);

                this.ScreenManager.SpriteBatch.Draw(howtoKnight, new Rectangle(20, yRoot + (352 * 3), 500, 352), Color.White);
                this.ScreenManager.SpriteBatch.DrawString(spriteFont, " Knights move in a crooked 'L' shape, moving two tiles \n diagonally, and then in one of two possible directions. \n The can jump friendly and opposing pieces.", new Vector2(520, yRoot + (352 * 3)), Color.White);

                this.ScreenManager.SpriteBatch.Draw(howtoBishop, new Rectangle(20, yRoot + (352 * 4), 500, 352), Color.White);
                this.ScreenManager.SpriteBatch.DrawString(spriteFont, " Bishops can move orthogonally in six directions by staying \n on their starting color.", new Vector2(520, yRoot + (352 * 4)), Color.White);

                this.ScreenManager.SpriteBatch.Draw(howtoQueen, new Rectangle(20, yRoot + (352 * 5), 500, 352), Color.White);
                this.ScreenManager.SpriteBatch.DrawString(spriteFont, " Queen movement is a combination of rook and bishop moves, \n both orthogonal and diagonal.", new Vector2(520, yRoot + (352 * 5)), Color.White);

                this.ScreenManager.SpriteBatch.Draw(howtoKing, new Rectangle(20, yRoot + (352 * 6), 500, 352), Color.White);
                this.ScreenManager.SpriteBatch.DrawString(spriteFont, " The king can move into immediate neighbors tiles, both \n orthogonal and diagonal, as well as castle in Shafran. \n The king cannot move into check.", new Vector2(520, yRoot + (352 * 6)), Color.White);

                this.ScreenManager.SpriteBatch.End();

                base.Draw(gameTime);
            }
        }


        #endregion

        #region Handle Input

        public override void HandleInput(HexChessBoard.PlayerComponents.InputState input, GameTime gameTime)
        {
            if ((input.CurrentKeyboardStates[(int)this.ControllingPlayer].IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down) || input.CurrentGamePadStates[(int)this.ControllingPlayer].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.DPadDown) || input.CurrentGamePadStates[(int)this.ControllingPlayer].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.LeftThumbstickDown)) && timeSinceIncrement > 0.03f && yRoot > -1832)
            {
                timeSinceIncrement = 0.0f;
                yRoot -= 4;
            }
            else if ((input.CurrentKeyboardStates[(int)this.ControllingPlayer].IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up) || input.CurrentGamePadStates[(int)this.ControllingPlayer].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.DPadUp) || input.CurrentGamePadStates[(int)this.ControllingPlayer].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.LeftThumbstickUp)) && timeSinceIncrement > 0.03f && yRoot < 92)
            {
                timeSinceIncrement = 0.0f;
                yRoot += 4;
            }
            else if (input.CurrentKeyboardStates[(int)this.ControllingPlayer].IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Back) || input.CurrentGamePadStates[(int)this.ControllingPlayer].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.B) || input.CurrentGamePadStates[(int)this.ControllingPlayer].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.Back))
            {
                this.ScreenManager.currentBackground = 0;
                exiting = true;
                this.ExitScreen();
            }

            base.HandleInput(input, gameTime);
        }

        #endregion
    }
}
